package com.tsxy.mall.mapper;

import com.tsxy.mall.entity.OrderDetails;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface OrderDetailsMapper {

    @Insert({
            "insert into order_details (book_id, order_id, price, count, result_price,book_type)",
            "values (#{bookId}, #{orderId}, #{price}, #{count},#{resultPrice},#{bookType}  )"
    })
    int insert(OrderDetails orderDetail);

    @Select({
            "select * from order_details where order_id = #{orderId}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="book_id", property="bookId", jdbcType=JdbcType.INTEGER),
            @Result(column="order_id", property="orderId", jdbcType=JdbcType.VARCHAR),
            @Result(column="price", property="price", jdbcType=JdbcType.DECIMAL),
            @Result(column="count", property="count", jdbcType=JdbcType.INTEGER),
            @Result(column="result_price", property="resultPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="book_type", property="bookType", jdbcType=JdbcType.VARCHAR),
            @Result(column = "book_id" ,property = "book",
                    one = @One(select = "com.tsxy.mall.mapper.BookMapper.selectById")),
            @Result(column = "book_id" ,property = "usedBook",
                    one = @One(select = "com.tsxy.mall.mapper.UsedBookMapper.getById"))
    })
    List<OrderDetails> selectByOrderId(String orderId);
}
